package com.mfangsoft.zhuangjialong.integration.product.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mfangsoft.zhuangjialong.common.context.UserContext;
import com.mfangsoft.zhuangjialong.common.model.ResponseMessage;
import com.mfangsoft.zhuangjialong.common.utils.SysConstant;
import com.mfangsoft.zhuangjialong.integration.product.model.BrandClassifyEntity;
import com.mfangsoft.zhuangjialong.integration.product.service.BrandClassifyService;
import com.mfangsoft.zhuangjialong.integration.productcategory.model.ProductCategoryEntity;
import com.mfangsoft.zhuangjialong.integration.productcategory.service.ProductCategoryService;

@Controller()
@RequestMapping("/server")
public class BrandClassifyController {

	@Autowired
	private BrandClassifyService brandClassifyService;
	
	
	@RequestMapping(value = "/addbrandclassify", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<String> addbrandClassify(@RequestBody BrandClassifyEntity brandClassifyEntity) {

		ResponseMessage<String> message = new ResponseMessage<>();

		try {
			brandClassifyService.addBrandClassify(brandClassifyEntity);

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			
			message.setResult(e.getMessage());
		}

		return message;

	}
	
	
	
	
	@RequestMapping(value = "/removebrandclassify/{id}", method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage<String> removeBrandClassify(@PathVariable  Long  id) {

		ResponseMessage<String> message = new ResponseMessage<>();

		try {
			brandClassifyService.removeBrandClassify(id);

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
			
			message.setResult(e.getMessage());
		}

		return message;

	}

	
	@RequestMapping(value = "/modifybrandclassify", method = RequestMethod.POST)
	@ResponseBody
	public ResponseMessage<String> modifyBrandClassify(@RequestBody BrandClassifyEntity brandClassifyEntity) {

		ResponseMessage<String> message = new ResponseMessage<>();

		try {
			brandClassifyService.modifyBrandClassify(brandClassifyEntity);

			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);

			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}
	
	
	@RequestMapping(value = "/querybrandclassifyentityall", method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage<List<BrandClassifyEntity>> queryProductCategoryALL(){
		ResponseMessage<List<BrandClassifyEntity>> message = new ResponseMessage<>();

		try {
			
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(brandClassifyService.queryBrandClassifyByUserId(UserContext.getCurrentUserId()));
			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}
	
	
	@RequestMapping(value = "/querybrandclassify/{p_id}", method = RequestMethod.GET)
	@ResponseBody
	public ResponseMessage<List<BrandClassifyEntity>> queryProductCategoryById(@PathVariable Long p_id){
		ResponseMessage<List<BrandClassifyEntity>> message = new ResponseMessage<>();

		try {
			
			message.setCode(SysConstant.SUCCESS_CODE);
			message.setMessage(SysConstant.SUCCESS_MSG);
			message.setResult(brandClassifyService.queryBrandClassifyByUserId(UserContext.getCurrentUserId(), p_id));
			return message;
		} catch (Exception e) {
			// TODO: handle exception

			message.setCode(SysConstant.FAILURE_CODE);
			message.setMessage(SysConstant.FAILURE_MSG);
		}

		return message;

	}

	
	
	
}
